/*-------------------------------------------------------------------------
 - Copyright (c) 2024-2025 [XD-AMCC TEAM]
 - [XD-AMCC] is licensed under Mulan PSL v2.
 - You can use this software according to the terms and conditions of the Mulan PSL v2.
 - You may obtain a copy of Mulan PSL v2 at:
 -          http://license.coscl.org.cn/MulanPSL2
 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
 - OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 - TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 - See the Mulan PSL v2 for more details.
 ------------------------------------------------------------------------*/


/*
 * @brief  List of errors in AMCC.
 *
 * This file #included by
 *      include/amcc_error.h,
 *      util/error.c.
 *
 * @author  WXQ#XDU
 * @date    2024.11
 */

#if defined(ERRCODE_DEFN) && defined(ERRCODE_DEF)

     ERRCODE_DEFN(  0, EC_OK,    "success" )
    ,ERRCODE_DEF (  0, EC_BUG,   "reach a BUG point at [%s:%d]: %s") // file,line#, desc

// group 1: 11~99,  system error

    ,ERRCODE_DEFN( 11, EC_OPENFILE,     "failed to open file - %s"  )  // error desc
    ,ERRCODE_DEF (  0, EC_READFILE,     "failed to read file - %s"  )  // error desc
    ,ERRCODE_DEF (  0, EC_EMPTY_FILE,   "zero byte file - %s"       )
    ,ERRCODE_DEF (  0, EC_WRITEFILE,    "failed to write file - %s" )  // error desc
    ,ERRCODE_DEF (  0, EC_ALLOC,        "failed to allocate memory in %s()" ) // function name

// group 2: 100 ~ 199,  lexcial errors diagnosed by Lexer

    // in lexer
    ,ERRCODE_DEFN( 100, EC_CHAR,             "unexpected character %s"    )
    ,ERRCODE_DEF (   0, EC_BLOCKCOMMENT,     "unclosed block comment starting from [%d:%d]"   )
    ,ERRCODE_DEF (   0, EC_LITERAL_OVERFLOW, "literal [%s] is out of range"  )
    ,ERRCODE_DEF (   0, EC_UNSUPPORT_KW,     "unsupported reserved word [%s]"   )
    ,ERRCODE_DEF (   0, EC_UNSUPPORT_TOKEN,  "unsupported token [%s]"   )

// group 3: 200 ~ 299,  syntax errors diagnosed by Parser

    // in parser
    ,ERRCODE_DEFN( 200, EC_EMPTY_INPUT,  "no tokens from lexer"    )
    ,ERRCODE_DEF (   0, EC_UNSUPPORT_NONDEF,  "unsupported Non-Definition-Declaration" )
    ,ERRCODE_DEF (   0, EC_TOKEN,        "unexpected token \"%s\""
                                         ", expect \"%s\"" ) // input-text,token_kind
    ,ERRCODE_DEF (   0, EC_DIMSZ_MISS,   "expect the length of dimension %d" )


// Following are for Semantic Analyzers

// group 4: 300 ~ 499,  errors related with names by symbol-table Builder

    ,ERRCODE_DEFN( 300, EC_DIMSZ_BAD,    "bad array size %d of dimension %d" )
    ,ERRCODE_DEF (   0, EC_DIM_TOOBIG,   "too many elements in array \"%s\"" )
    ,ERRCODE_DEF (   0, EC_INIT_TOOLEN,  "too many initializers, meet %d, expect %d in dimension %d" )
    ,ERRCODE_DEF (   0, EC_INIT_TOODEEP, "too deep nested initializer, have %d, expected %d" )
    ,ERRCODE_DEF (   0, EC_INIT_NOBRACE, "array-initializer must be a brace-enclosed list for dimension %d" )
    ,ERRCODE_DEF (   0, EC_INIT_HASBRACE, "unexpected brace-enclosed-initializer for a scalar" )

    ,ERRCODE_DEF (   0, EC_REDEFINE,     "redefinition of %s name \"%s\""
                                         ", previous definition is here [%d:%d]" )
    ,ERRCODE_DEF (   0, EC_UNDEFINED,    "undefined %s name \"%s\"" )
    ,ERRCODE_DEF (   0, EC_LABEL_BADPOS, "bad label definition \"%s\""
                                         ", it can only appear in a function body" )
    ,ERRCODE_DEF (   0, EC_VAR_VOID,     "variable/parameter type cann't be \"void\"" )
    ,ERRCODE_DEF (   0, EC_REFER_KIND,   "\"%s\" is not a %s name" )
    ,ERRCODE_DEF (   0, EC_REFER_NOTARR, "\"%s\" is not an array name" )
    ,ERRCODE_DEF (   0, EC_REFER_NDIMS,  "expect %d subscript%s for array \"%s\"" )
    ,ERRCODE_DEF (   0, EC_FUNCALL_NUM,  "expect %d argument%s to invoke %s()" )

    ,ERRCODE_DEF (   0, EC_FUNCALL_TYPE, "incompatible type \"%s\" with \"%s\" of argument %d to invoke %s()" )
    ,ERRCODE_DEF (   0, EC_OPTR_TYPE1,   "incompatible type \"%s\" of left operand for operator '%s'" )
    ,ERRCODE_DEF (   0, EC_OPTR_TYPE2,   "incompatible type \"%s\" of right operand for operator '%s'" )
    ,ERRCODE_DEF (   0, EC_INIT_TYPE ,   "incompatible type \"%s\" of initializer" )

// group 5: 500 ~ ,  semantic errors diagnosed by IR-code generator, ...

    ,ERRCODE_DEFN( 500, EC_NO_MAIN,      "no main() in global scope" )
    ,ERRCODE_DEF (   0, EC_BAD_MAIN,     "global \"main\" MUST be the entry function" )
    ,ERRCODE_DEF (   0, EC_MISSRET_STMT, "missing return at the end of function \"%s\"" )
    ,ERRCODE_DEF (   0, EC_MISSRET_VAL,  "missing return value for function \"%s\"" )
    ,ERRCODE_DEF (   0, EC_EXTRA_RET_VAL,"unexpected return-expression for function \"%s\"" )
    ,ERRCODE_DEF (   0, EC_NOTINLOOP,    "keyword \"%s\" is not in a loop" )


// END-OF-ERROR-CODES
#endif

// END-OF-FILE
